import pymysql
from loguru import logger

class DorisDatabase:
    def __init__(self, db_config):
        self.db_config = db_config

    def execute_query(self, query):
        logger.info(f"############执行sql-query: {query} ################")
        try:
            connection = pymysql.connect(**self.db_config)
            with connection.cursor() as cursor:
                cursor.execute(query)
                result = cursor.fetchall()
            logger.info(f"############ sql执行成功，结果：{result}")
            return result
        except Exception as e:
            logger.error(f"Database query failed: {e}")
            return None
        finally:
            if connection:
                connection.close()